package baseball.controller;

import baseball.domain.User;
import baseball.mapper.UserMapper;
import baseball.support.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@RequestMapping("member")
@Controller
public class MemberController extends BaseController{

    @Autowired
    private UserMapper userMapper;

    /**
     * 修改密码
     * @param pwd
     * @param pwd2
     * @return
     */
    @RequestMapping("modify")
    public String modify(String pwd, String pwd2, HttpSession session, Model model){
        User user = (User) session.getAttribute("sessionUser");
        if(!user.getPassword().equals(pwd)){
            model.addAttribute("msg","原密码错误");
            return "error";
        }
        user.setPassword(pwd2);
        userMapper.updateByPrimaryKeySelective(user);
        session.setAttribute("sessionUser",user);
        return "redirect:/index.do";
    }

}
